var t = getApp();

Page({
    data: {
        myAddList: "",
        addressBoo: !0,
        textarea: !1,
        provinceBoo: !0,
        cityBoo: !0,
        height: 110
    },
    onShareAppMessage: function(t) {},
    onLoad: function(a) {
        wx.showLoading({
            title: "加载中",
            mask: !0
        });
        var e = wx.getStorageSync("logs") || "";
        e || (t.getToken(), e = wx.getStorageSync("logs"));
        var i = this;
        this.setData({
            addrId: a.addrId,
            token: e
        }), wx.request({
            url: t.globalData.httpOne + "mall/addr/get/" + i.data.addrId,
            success: function(t) {
                200 == t.data.code && (wx.hideLoading(), i.setData({
                    myAddList: t.data.data
                }));
            },
            fail: function() {
                wx.showToast({
                    title: "系统繁忙，请稍后重试",
                    icon: "none",
                    duration: 2e3
                });
            }
        });
    },
    bindfocus: function(t) {
        var a = this.data.myAddList;
        a.receiverMobileMask = "", this.setData({
            myAddList: a
        });
    },
    formSubmit: function(a) {
        var e = this, i = a.detail.value;
        if (i.username) {
            var o = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
            if (i.phone == e.data.myAddList.receiverMobileMask && "" != i.phone) i.phone = e.data.myAddList.receiverMobile; else if (!o.test(i.phone)) return void wx.showToast({
                title: "请输入11位手机号",
                icon: "none",
                duration: 2e3
            });
            if (i.address) if (i.receiverAddress) {
                i.check = i.check ? 1 : 0;
                e = this;
                wx.request({
                    url: t.globalData.httpOne + "mall/addr/edit",
                    method: "post",
                    header: {
                        "content-type": "application/x-www-form-urlencoded"
                    },
                    data: {
                        token: e.data.token,
                        addrId: e.data.addrId,
                        receiverName: i.username,
                        receiverMobile: i.phone,
                        area: i.address,
                        areaCode: e.data.myAddList.areaCode,
                        receiverAddress: i.receiverAddress,
                        currentDefault: i.check
                    },
                    success: function(t) {
                        200 == t.data.code && wx.navigateBack({
                            delta: 1
                        });
                    },
                    fail: function() {
                        wx.showToast({
                            title: "系统繁忙，请稍后重试",
                            icon: "none",
                            duration: 2e3
                        });
                    }
                });
            } else wx.showToast({
                title: "请输入详细地址",
                icon: "none",
                duration: 1e3
            }); else wx.showToast({
                title: "请选择收货地址",
                icon: "none",
                duration: 1e3
            });
        } else wx.showToast({
            title: "请输入姓名",
            icon: "none",
            duration: 1e3
        });
    },
    btnDel: function() {
        var a = wx.getStorageSync("addrList") || "", e = "", i = this.data.addrId;
        if (0 != a.length && a.forEach(function(t, a) {
            1 == t.currentDefault && (e = t.addrId);
        }), e != i) {
            var o = this;
            wx.showModal({
                content: "确定要删除该地址吗？",
                confirmColor: "#3b4ca9",
                success: function(e) {
                    e.confirm && wx.request({
                        url: t.globalData.httpOne + "mall/addr/delete/" + o.data.addrId + "/" + o.data.token,
                        success: function(t) {
                            200 == t.data.code && (0 != a.length && a.forEach(function(t, e) {
                                if (t.addrId != o.data.addrId) ; else {
                                    a.splice(e, 1);
                                    try {
                                        wx.setStorageSync("addrList", a);
                                    } catch (t) {}
                                }
                            }), wx.navigateBack({
                                delta: 1
                            }));
                        },
                        fail: function() {
                            wx.showToast({
                                title: "系统繁忙，请稍后重试",
                                icon: "none",
                                duration: 2e3
                            });
                        }
                    });
                }
            });
        } else wx.showToast({
            title: "当前选中地址不可删除~",
            icon: "none",
            duration: 2e3
        });
    },
    choosearea: function() {
        this.setData({
            textarea: !0
        });
        var a = this;
        this.animation.translateX(0).step(), wx.request({
            url: t.globalData.httpOne + "mall/addr/listNation/1",
            success: function(t) {
                200 == t.data.code && a.setData({
                    provinceList: t.data.data
                });
            },
            fail: function() {
                wx.showToast({
                    title: "系统繁忙，请稍后重试",
                    icon: "none",
                    duration: 2e3
                });
            }
        }), this.setData({
            addressBoo: !1,
            animationData: this.animation.export()
        });
    },
    onShow: function() {
        var t = wx.createAnimation({
            duration: 800,
            timingFunction: "ease"
        });
        this.animation = t;
    },
    tapProvince: function(a) {
        this.setData({
            province: "",
            city: "",
            district: "",
            districtList: "",
            cityList: ""
        });
        var e = a.target.id, i = a.target.dataset.index, o = a.target.dataset.province, n = this;
        this.setData({
            provinceIndex: i,
            province: o
        }), n.data.provinceBoo && wx.request({
            url: t.globalData.httpOne + "mall/addr/listNation/" + e,
            success: function(t) {
                200 == t.data.code && n.setData({
                    cityList: t.data.data,
                    cityIndex: "none",
                    districtIndex: "none",
                    provinceBoo: !0
                });
            }
        }), n.setData({
            provinceBoo: !1
        });
    },
    tapCity: function(a) {
        this.setData({
            city: "",
            district: "",
            districtList: ""
        });
        var e = a.target.id, i = a.target.dataset.index, o = a.target.dataset.city, n = this;
        this.setData({
            cityIndex: i,
            city: o
        }), n.data.cityBoo && wx.request({
            url: t.globalData.httpOne + "mall/addr/listNation/" + e,
            success: function(t) {
                200 == t.data.code && n.setData({
                    districtList: t.data.data,
                    districtIndex: "none",
                    cityBoo: !0
                });
            }
        }), n.setData({
            cityBoo: !1
        });
    },
    tapDistrict: function(t) {
        this.setData({
            district: ""
        });
        t.target.id;
        var a = t.target.dataset.index, e = t.target.dataset.code, i = t.target.dataset.district, o = this.data.province + "-" + this.data.city + "-" + i, n = this.data.myAddList;
        n.area = o, n.areaCode = e, this.setData({
            districtIndex: a,
            district: i,
            myAddList: n
        }), this.animation.translateX(1200).step(), this.setData({
            addressBoo: !0,
            animationData: this.animation.export(),
            textarea: !1
        });
    },
    closesearea: function() {
        this.setData({
            textarea: !1
        }), this.animation.translateX(1200).step(), this.setData({
            addressBoo: !0,
            animationData: this.animation.export()
        });
    },
    bindlinechange: function(t) {
        t.detail.heightRpx > 110 ? this.setData({
            height: t.detail.heightRpx
        }) : this.setData({
            height: 110
        });
    }
});